package de.koller.aframe.plain;

import java.util.Arrays;

public class PlainRasterFloat {
	
	public final int width, height;
	public final float[] data;

	public PlainRasterFloat( float[] pixel, int width, int height ) {
		this.width = width;
		this.height = height;
		this.data = pixel;
	}
	
	public PlainRasterFloat( int width, int height ) {
		this( new float[width*height], width, height );
	}
	
	public void clear( float v ) {
		Arrays.fill( data, v );
	}
	
	public float getValue( int x, int y ) {
		return getValue( getOffset( x, y ) );
	}
	
	public void setValue( float value, int x, int y ) {
		setValue( value, getOffset( x, y ) );
	}
	
	public int getOffset( int x, int y ) {
		if( x < 0 || y < 0 || x >= width || y >= height )
			return -1;
		return y * width + x;
	}
	
	private float getValue( int offset ) {
		if( offset == -1 )
			return 0xffffffff;
		return data[ offset ];
	}
	
	private void setValue( float value, int offset ) {
		if( offset == -1 )
			return;
		data[ offset ] = value;
	}
	
}
